﻿using System.Collections;
using System.Collections.Generic;
using System.Data.SqlClient;
using com.fukefu.sql;

namespace com.fukefu.tools
{
    public class KeywordType
    {
        Hashtable ht = new Hashtable();
        //初始化
        public KeywordType()
        {
            SqlServerOperate sql = new SqlServerOperate();
            SqlDataReader re = sql.Query("select * from 全局设置.dbo.[_bt_关键字分类]");
            while (re.Read())
            {
                string[] str = { re["word"].ToString(), re["shortword"].ToString() };
                ht.Add(re["ktid"].ToString(), str);
            }
            re.Close();
            sql.Close();
        }
        //获取集合
        public List<string> List()
        {
            List<string> list = new List<string>();
            foreach (DictionaryEntry d in ht)
            {
                list.Add((d.Value as string[])[0]);
            }
            return list;
        }
        //获取分类Id
        public string GetKtid(string word)
        {
            foreach (DictionaryEntry d in ht)
            {
                if ((d.Value as string[])[0].Equals(word))
                {
                    return d.Key.ToString();
                }
            }
            return "";
        }
        //获取分类名称
        public string Get(string ktid)
        {
            if (ht.Contains(ktid))
            {
                return (ht[ktid] as string[])[0];
            }
            return "";
        }
        //获取短分类名称
        public string GetShortTypeName(string ktid)
        {
            if (ht.Contains(ktid))
            {
                return (ht[ktid] as string[])[1];
            }
            return "";
        }
    }
}
